package gamehistory.challenge;

import edu.neu.ccs.demeterf.lib.Map;
import scg.Util;
import scg.gen.AccountSolveTrans;
import scg.gen.SolveTrans;
import scg.gen.Var;
import utils.FormatUtilities;
import gamehistory.utils.xml.XMLModel;

/**
 * 
 * @author Brent Kersanske
 *
 */
public class SolveModel extends XMLModel {

	private static final String PROFIT			 = "profit";
	private static final String LOSS			 = "loss";
	
	private static final String SOLUTION 		 = "solution";
	private static final String SOLVER			 = "solver";
	private static final String FSAT	 	     = "fsat";
	private static final String DIFF_FROM_ACCEPT = "diffFromAccept";
	private static final String ACCOUNT_CHANGE   = "accountChange";
	
	private String solver;
	private String result;
	private double fSatisfaction;
	private double diffFromAcceptPrice;
	private double accountChange;
	
	/**
	 * Constructor
	 * @param solveTransaction
	 */
	public SolveModel(String solvingPlayer, SolveTrans solveTransaction) {
		super(SOLUTION);
		this.solver 	 = solvingPlayer;
	}

	/**
	 * 
	 * @param acceptedPrice
	 * @param accountSolveTransaction
	 */
	public void assimilateAccountSolveTransaction(double acceptedPrice, AccountSolveTrans accountSolveTransaction) {
		this.fSatisfaction 		 = accountSolveTransaction.getFsat();
		this.diffFromAcceptPrice = this.fSatisfaction - acceptedPrice;
		if(accountSolveTransaction.getAmount() >= acceptedPrice) {
			this.result 	   = PROFIT;
			this.accountChange = accountSolveTransaction.getAmount();
		} else {
			this.result 	   = LOSS;
			this.accountChange = -acceptedPrice;
		}
	}

	public String getResult() {
		return this.result;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void buildModel() {
		addAttribute(SOLVER,		   this.solver);
		addAttribute(FSAT, 			   FormatUtilities.formatDouble(this.fSatisfaction));
		addAttribute(DIFF_FROM_ACCEPT, FormatUtilities.formatDouble(this.diffFromAcceptPrice));		
		addAttribute(ACCOUNT_CHANGE,   FormatUtilities.formatDouble(this.accountChange));
	}
}
